package com.yidu.DailyFinalTreatment.controller;

import com.yidu.BusinessParameters.entity.SecurityAccruedEntity;
import com.yidu.BusinessParameters.service.SecurityAccruedService;
import com.yidu.DailyFinalTreatment.entity.BondSecurity;
import com.yidu.DailyFinalTreatment.service.BondSecurityService;
import com.yidu.Util.util.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class BondSecurityController {
    @Resource
    private BondSecurityService bondSecurityService;
    @Resource
    private Dbutil dbUtil;
    @Resource
    private SecurityAccruedService securityAccruedService;

    @RequestMapping("bondSecurity")
    public Map bondSecuritySelect(String date){
        System.out.println("123");
        List<BondSecurity> bondSecurityList = bondSecurityService.selectBondSecurity(date);
        Map map =new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("data",bondSecurityList);
        System.out.println(map.get("data"));
        System.out.println(bondSecurityList);
        return map;

    }

    //债券利息统计
    @RequestMapping("BondSecuritiesMo")
    public int BondSecuritiesMo(String Securities) {
        int i =0;
        System.out.println(Securities);
        System.out.println("进来了===============================================iii");
        List<BondSecurity> bondSecurityList = SysUtil.jsonToArrayList(Securities,BondSecurity.class);
        for (BondSecurity bondSecurity:bondSecurityList) {
            SecurityAccruedEntity securityAccruedEntity =new SecurityAccruedEntity();
            securityAccruedEntity.setSecurityDate(bondSecurity.getSecurityInventorsTime());
            String securityAccruedId =dbUtil.getMaxId3(TableIdUtil.SASD,TableNameUtil.SI, TableTimeUtil.SASTime,securityAccruedEntity.getSecurityDate());
            System.out.println("securityAccruedId"+securityAccruedId);
            securityAccruedEntity.setSecurityAccruedId(securityAccruedId);
            securityAccruedEntity.setFundId(bondSecurity.getFundId());
            securityAccruedEntity.setCashId("C20220628001");
            securityAccruedEntity.setMoneyFlow(3);
            securityAccruedEntity.setMoney(bondSecurity.getInterest());

            securityAccruedEntity.setBusinessType(1);
            securityAccruedEntity.setSecurityId(bondSecurity.getSecurityId());
            System.out.println("securityAccruedEntity"+securityAccruedEntity);
            i=securityAccruedService.securityAccruedinsert(securityAccruedEntity);
            System.out.println(i+"插入证券应收应付的I===========================");
            if (i>0){
                i=securityAccruedService.deleteSecurities(securityAccruedEntity);
                if (i>0){
                    i=securityAccruedService.securityAccruedinsert(securityAccruedEntity);
                }
            }
        }
        return i;
    }

}
